package main;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;

import genericorderedlist.*;

public class GenericOrderedListTest {
	public static void main(String[] Args) throws InstantiationException, 
													IllegalAccessException, 
													IllegalArgumentException, 
													InvocationTargetException, 
													NoSuchMethodException, SecurityException {
		OrderedList<Integer> il = new GenericOrderedList.NatOrderBuilder<Integer>()
				.list(ArrayList.class).build();
		for (int i = 4; i < 7; i += 2)
			il.add(i);
		for (int i = 5; i < 8; i += 2)
			assert il.add(i);
		for (int i = 0; i < 4; i++)
			assert il.add(i);
		for (int i = 8; i < 10; i++)
			assert il.add(i);
		for (int i = 0; i < 10; i++)
			assert !(il.add(i));
		assert il.toString().equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
		for (int i = 0; i < 10; i++)
			assert il.contains(i);
		OrderedList<Integer> il2 = new GenericOrderedList.Builder<Integer>(
				il.getComparator()).iterator(il.iterator()).build();
		OrderedList<Integer> il3 = new GenericOrderedList.Builder<Integer>(
				il.getComparator()).iterator(il.iterator()).list(ArrayList.class).build();
		assert il.equals(il);
		assert il.equals(il2);
		assert il2.equals(il);
		assert il2.equals(il3);
		assert il3.equals(il);
		assert il.compareTo(il) == 0;
		assert il.compareTo(il2) == 0;
		assert il2.compareTo(il) == 0;
		assert !il.remove(-1);
		assert !il.remove(10);
		assert il.toString().equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
		assert il.remove(0);
		assert il.compareTo(il2) > 0;
		assert il2.compareTo(il) < 0;
		assert il2.remove(0);
		assert il.remove(9);
		assert il.compareTo(il2) < 0;
		assert il2.compareTo(il) > 0;
		assert il2.remove(9);
		assert il.remove(5);
		assert il.toString().equals("[1, 2, 3, 4, 6, 7, 8]");
		assert il.size() == 7;
		assert il.compareTo(il2) > 0;
		assert il2.compareTo(il) < 0;
		OrderedList<Calendar> cl1 = new GenericOrderedList.NatOrderBuilder<Calendar>()
				.iterator(
						Arrays.<Calendar> asList(new GregorianCalendar(2007, 1,
								27), new GregorianCalendar(2004, 7, 20)).iterator())
				.build();
		OrderedList<GregorianCalendar> cl2 = new GenericOrderedList.NatOrderBuilder<GregorianCalendar>()
				.iterator(
						Arrays.<GregorianCalendar> asList(
								new GregorianCalendar(2001, 8, 21),
								new GregorianCalendar(1972, 10, 17)).iterator()).build();
		assert cl1.compareTo(cl1) == 0;
		assert cl2.compareTo(cl2) == 0;
		assert cl1.compareTo(cl2) > 0;
		
		System.out.println("TESTS PASSED!");
	}
}
